<?php
	class User {
		static function register($user, $password, $email) {
			require "conn.php";
			$rs = $conn->query("select user from users where user='".(string)$user."' or email='".(string)$email."'");
			if ($rs->num_rows > 0) {
				print "DUPLICATE";
				require "conn_close.php";
				return;
			}
			$conn->query("insert into users (user, password, email) values ('".(string)$user."','".(string)$password."','".(string)$email."')");
			$conn->query("insert into posts (title, content) values ('Гишүүн:".(string)$user."','".(string)$user." гишүүний хуудас')");
			$conn->query("insert into posts (title, content) values ('Гишүүний хэлэлцүүлэг:".(string)$user."','".(string)$user." гишүүний хэлэлцүүлгийн хуудас')");
			require "constant.php";
			$conn->query("insert into actions (type, user, title, content, date) ".
								"values ('".ACTION_AUTOCREATEPOST."', '".(string)$user."','Гишүүн:"
								.(string)$user."','".(string)$user." гишүүний хуудас',SYSDATE())");
			$conn->query("insert into actions (type, user, title, content, date) ".
								"values ('".ACTION_AUTOCREATEPOST."', '".(string)$user."','Гишүүний хэлэлцүүлэг:"
								.(string)$user."','".(string)$user." гишүүний хэлэлцүүлгийн хуудас',SYSDATE())");
			require "conn_close.php";
		}
		static function login($user, $password) {
			require "conn.php";
			$rs = $conn->query("select user from users where user='".(string)$user."' and password='".(string)$password."'");
			if ($rs->num_rows == 1) {
				return "SUCCESS";
			}
			require "conn_close.php";
		}
	}
?>
